package com.ccb.sc.goods.vo;

import com.ccb.sc.goods.enums.GoodsType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 列表视图实体
 * </p>
 *
 * @author ken
 * @date 2020-08-24
 */
@Data
@ApiModel
@Accessors(chain = true)
public class AppGoodsListVo implements Serializable {

    private Long id;

    @ApiModelProperty(value = "商品名称")
    private String name;

    @ApiModelProperty(value = "推荐语")
    private String recommendedWords;

    @ApiModelProperty(value = "产品编码")
    private String spu;

    @ApiModelProperty("分类id")
    private Long categoryId;

    @ApiModelProperty(value = "分类名称")
    private String categoryName;

    @ApiModelProperty("品牌id")
    private Long brandId;

    @ApiModelProperty(value = "品牌名称")
    private String brandName;

    @ApiModelProperty(value = "图片")
    private String picture;

    @ApiModelProperty(value = "市场价格")
    private BigDecimal marketPrice;

    @ApiModelProperty(value = "销售价格")
    private BigDecimal salePrice;

    @ApiModelProperty(value = "积分价格")
    private int exchangePoints;

    @ApiModelProperty("销量")
    private Integer sales;

    @ApiModelProperty("库存")
    private Long stock;

    @ApiModelProperty("最新上架时间")
    private LocalDateTime lastOnsaleTime;

    public GoodsType getGoodsType() {
        if (lastOnsaleTime != null && lastOnsaleTime.isAfter(LocalDateTime.now().minusMonths(1))) {
            return GoodsType.NEW_STOCK;
        }
        if (sales > 10) {
            return GoodsType.HOT;
        }
        return null;
    }

}